package org.obs.core.hibernate.operations;

import org.hibernate.Query;
import org.hibernate.Session;
import org.obs.core.HibernateOperation;

public class GetUserIdByNickOperation implements HibernateOperation <Long> {

	private String nick;

	public GetUserIdByNickOperation(String nick) {
		this.nick = nick;
	}

	private static final String queryString = "select u.id from User as u where u.nick = :nick"; 
	
	public Long execute(Session session) {
		Query query = session.createQuery(queryString);
		query.setParameter("nick", nick);
		return (Long) query.uniqueResult();
	}

}
